<?php

/**
* JSON-Ajax Reciever
* Expects a Json String as POST Parameter
* 
* @package JOEL
*/

require_once("bootstrap.php");

$myobj = json_decode(preg_replace('/[\n\r]+/', '\n', stripslashes($_REQUEST['json']))) 
	or die($_SESSION['joel']->jsonResponse(array('error' => 'data could not be parsed from json string')));

$myclassname = isset($myobj->classname) ? $myobj->classname : 'joel';
$myfunction = $myobj->method;

if($myclassname != 'joel') {
	$class = new $myclassname;
} else {
	$class = $_SESSION['joel'];
}

if(method_exists($class,$myfunction)) {
	$param = isset($myobj->parameter) ? $myobj->parameter : false;
	$class->$myfunction($param);
	
} else {
	die('error: Method "'.$myfunction.'" does not exists in class "'.$myclassname.'"');
}

?>